package Aleehot100;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: c045
 * Package: Aleehot100
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/7/16 08:30
 * @Version 1.0
 * @Since 1.0
 */
public class c045 {
    public static void main(String[] args) {

    }
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public static List<Integer> res = new ArrayList<>();
    public static List<Integer> rightSideView(TreeNode root) {
        res.clear();
        process(root, 0);
        return res;
    }

    private static void process(TreeNode node, int cnt) {
        if(node == null) {
            return;
        }
        if(res.size() == cnt) {
            res.add(node.val);
        }
        process(node.right, cnt + 1);
        process(node.left, cnt + 1);
    }
}
